package Cart_Servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Cart_Function.Cart_Function;
import Cart_Utils.Cart;
import Goods_Utils.Good;

/**
 * Servlet implementation class DoCart_Servlet
 */
@WebServlet("/DoCart_Servlet")
public class DoCart_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoCart_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=utf-8");
		String user = (String) request.getSession().getAttribute("UserName");
		ArrayList<Cart> carts = new Cart_Function().getUserCart(user);
		if(carts.size()==0){
			request.setAttribute("msg", "购物车为空");
			request.getRequestDispatcher("AllGoods_Servlet").forward(request, response);
		}else{
			
			request.getSession().setAttribute("carts", carts);
			request.getRequestDispatcher("cart.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
